import { Strategy, IStrategyOptions } from 'passport-local';
import { PassportStrategy } from '@nestjs/passport';
import { BadRequestException, Injectable } from '@nestjs/common';
import { AuthService } from './auth.service';

@Injectable()
export class localStrategy extends PassportStrategy(Strategy,'local'){
    constructor(private readonly authService: AuthService) {
        super();
    }

    async validate(username: string, password: string){
        const user = await this.authService.validateUser(username, password);
        if(!user) {
            throw new BadRequestException('登录失败！')
        }
        return user
    }
}